package _021_10_3

import "math"

type MinStack2 struct {
	stack []int
	temp  []int
}

func Constructor2() MinStack2 {
	return MinStack2{
		stack: []int{},
		temp:  []int{},
	}
}

func (this *MinStack2) Push(val int) {
	this.stack = append(this.stack, val)
	if len(this.temp) == 0 {
		this.temp = append(this.temp, val)
		return
	}

	this.temp = append(this.temp, int(math.Min(float64(val), float64(this.temp[len(this.temp)-1]))))
}

func (this *MinStack2) Pop() {
	this.stack = this.stack[0 : len(this.stack)-1]
	this.temp = this.temp[0 : len(this.temp)-1]
}

func (this *MinStack2) Top() int {
	return this.stack[len(this.stack)-1]
}

func (this *MinStack2) GetMin() int {
	return this.temp[len(this.temp)-1]
}
